package router

import (
	"chat/docs"
	"chat/service"
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
	"golang.org/x/net/websocket"
)

func Router() *gin.Engine {
	r := gin.Default()
	r.Use(AllowAllCors())
	docs.SwaggerInfo.BasePath = ""
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	r.GET("/index", service.GetIndex)
	r.GET("/user/getUserList", service.GetUserList)
	r.GET("/user/createUser", service.CreateUser)
	r.GET("/user/delUser", service.DelUser)
	r.POST("/user/updateUser", service.UpdateUser)
	r.POST("/user/loginByNameAndPassword", service.LoginByNameAndPassword)
	r.GET("/ws/chat", func(c *gin.Context) {
		websocket.Handler(service.Chat).ServeHTTP(c.Writer, c.Request)
	})
	return r
}
